import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Element, { Loading } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/global.css'
import less from 'less'
import './assets/fonts/iconfont.css'
import axios from 'axios'
import Treetable from 'vue-table-with-tree-grid'

Vue.use(Treetable)
Vue.use(less)
Vue.use(Element)

Vue.prototype.$fullLoading = (wer) => {
  const loading = Loading.service({ // 声明一个loading对象
    target: document.querySelector(wer)
  })
  setTimeout(function () { // 设定定时器，超时5S后自动关闭遮罩层，避免请求失败时，遮罩层一直存在的问题
    loading.close() // 关闭遮罩层
  }, 10000)
  return loading
}

axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
axios.interceptors.request.use(config => {
  // console.log(config)
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 在最后必须 return config
  return config
})

Vue.prototype.$http = axios

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
